package com.example.james.recyclerviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Fruit> fruitList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFruits();
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
//        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
//        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new FruitAdapter(fruitList));
    }

    private void initFruits() {
        for (int i = 0; i < 3; i++){
            Fruit apple = new Fruit("apple", R.drawable.apple_pic);
            Fruit banana = new Fruit("banana", R.drawable.banana_pic);
            Fruit cherry = new Fruit("cherry", R.drawable.cherry_pic);
            Fruit grape = new Fruit("grape", R.drawable.grape_pic);
            Fruit mango = new Fruit("mango", R.drawable.mango_pic);
            Fruit orange = new Fruit("orange", R.drawable.orange_pic);
            Fruit pear = new Fruit("pear", R.drawable.pear_pic);
            fruitList.add(apple);
            fruitList.add(banana);
            fruitList.add(cherry);
            fruitList.add(grape);
            fruitList.add(mango);
            fruitList.add(orange);
            fruitList.add(pear);
        }
    }
}
